# -*- coding: utf-8 -*-
# @Time    : 2021/8/31 17:17
# @Author  : BrandonGT
# @FileName: 09_PyQt5_QLineEdit.py

# 1. 导入包和模块
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import sys

# 2. 创建一个应用程序对象
app = QApplication(sys.argv)

# 3. 创建控件
window = QWidget()

# 3.1 设置控件
window.setWindowTitle("")
window.resize(500, 500)

showlable = QLabel(window)
showlable.setText("测试")
showlable.resize(100, 30)
showlable.move(200, 50)
showlable.hide()

account = QLineEdit(window)
account.resize(100, 30)
account.move(200, 100)
account.setPlaceholderText("请输入账号")
account.setClearButtonEnabled(True)

password = QLineEdit(window)
password.resize(100, 30)
password.move(200, 150)
password.setEchoMode(QLineEdit.Password)

login = QPushButton(window)
login.setText("登录")
login.resize(100, 30)
login.move(200, 200)

def _login():
    correct_account = "bd"
    correct_password = "hypergryph"

    get_account = account.text()
    get_password = password.text()
    # print(get_account)
    # print(get_password)

    if get_account == correct_account and get_password == correct_password:
        showlable.setText("登录成功")
        account.setText("")
        password.setText("")
    elif get_password != correct_password:
        showlable.setText("密码错误")
        password.setText("")
    elif get_account != correct_account:
        showlable.setText("账号错误")
        account.setText("")
    else:
        showlable.setText("请输入账号和密码")

    showlable.show()

login.pressed.connect(_login)


# 3.2 展示控件
window.show()

# 4. 应用程序执行，进入消息循环
sys.exit(app.exec_())